package com.coderman.modelfly.service;

import com.coderman.modelfly.utils.JdbcUtils;

import java.util.List;
import java.util.Map;

/**
 * Created by 58-daojia on 2017-10-18.
 *
 * @author: fanchunshuai
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
public class DbQueryService {
    /**
     * 查询数据库中所有表中所有的字段信息
     */
    String metaSql = "";

    /**
     * 查询数据库中所有表的注释信息
     */
    String tableSql = "";


    public DbQueryService(String configPath){
        //1.初始化连接db的配置
        try {
            JdbcUtils.initDBConnection(configPath);
        } catch (Exception e) {
            e.printStackTrace();
        }
        metaSql = "SELECT TABLE_NAME,COLUMN_NAME,COLUMN_TYPE AS TYPE,COLUMN_COMMENT FROM information_schema.columns WHERE TABLE_SCHEMA = '"+ JdbcUtils.getDbName()+"'";
        tableSql = "SELECT TABLE_NAME,TABLE_COMMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = '"+JdbcUtils.getDbName()+"'";

    }




    public Map<String,List<String>>  getColumnMap() throws Exception {

       return JdbcUtils.exeColumnSearchSql(metaSql);

    }

    public Map<String,String>  getDBMap() throws Exception {

        return JdbcUtils.exeDBSearchSql(tableSql);
    }

}
